<!DOCTYPE HTML>
<html lang="zh-CN">
<head>
  	<meta charset="UTF-8">
  	<meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
  	<meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
  	<title>登录win</title>
  	<link rel="stylesheet" type="text/css" href="../../css/api.css" />
    <link rel="stylesheet" type="text/css" href="../../css/aui.css" />
  	<link rel="stylesheet" type="text/css" href="../../css/common.css">
    <style>
        body{background: #fff !important;}
        .aui-bar.aui-bar-light{background-image:none;}
        .aui-btn-block.aui-btn-sm{width: 7.33rem;height: 45px;line-height: 45px;margin: 0 auto;background: #00c800;display: flex;align-items: center;justify-content: center;
          color: #fff;font-size: 18px;border-radius: 0.6rem;}
        .accountNumber .aui-list .aui-list-item-inner{min-height: 1.2rem;height: 1.2rem;line-height: 1.2rem}
        .accountNumber .aui-list-item-label,.accountNumber .aui-list-item-input{min-height: 1.2rem;height: 1.2rem;line-height: 1.2rem}
        .accountNumber .aui-btn-block.aui-btn-sm{width: 7.33rem;height: 1.2rem;line-height: 1.2rem;background: #ff4c41;margin:2rem auto 0;
          color: #fff;font-size:0.48rem;border-radius: 0.5rem;}
    </style>
</head>
<body id="wrap" style="position:relative">
    <header class="aui-bar aui-bar-nav aui-bar-light sg-color-font1" id="aui-header">
        <a class="aui-pull-left"  tapmode onclick="closeWinFun()">
            <span class="aui-iconfont aui-icon-left sg-text-size36 sg-color-font1"></span>
        </a>
    </header>
    <div class="container">
        <div class="wxBox" >
            <img style="margin-top:1rem;width:100%;height:auto;" src="../../image/loginImg.png" alt="">
            <p style="color:#ff4c41;font-size:0.4rem;text-align:center;padding-top:0.72rem;margin-bottom:1.84rem;">省钱高达90%的<br>购物优惠券搜索平台</p>
            <p><div class="aui-btn aui-btn-block aui-btn-sm" tapmode onclick="wxlogin()"><i class="aui-iconfont aui-icon-wechat"></i>微信登录</span></div></p>
        </div>
        <div class="accountNumber" style="display:none">
            <img style="margin:2rem auto;width:2rem;height:2rem;" src="../../image/sheng.png" alt="">
            <div class="aui-content aui-margin-b-15" style="margin: 0 1rem;">
                <ul class="aui-list aui-form-list" style="background-image:none;">
                    <li class="aui-list-item" style="min-height: 1.2rem;height:1.2rem;padding:0;">
                        <div class="aui-list-item-inner">
                            <div class="aui-list-item-label" style="width:20%">
                                <i class="aui-iconfont aui-icon-mobile" style="margin: 0 auto;font-size: 0.5rem;"></i>
                            </div>
                            <div class="aui-list-item-input">
                                <input id="numberLogin" style="height:1.2rem;line-height:1.2rem;font-size:0.4rem" type="number" placeholder="请输入手机号">
                            </div>
                        </div>
                    </li>
                    <li class="aui-list-item" style="min-height: 1.2rem;height:1.2rem;padding:0;">
                        <div class="aui-list-item-inner">
                            <div class="aui-list-item-label" style="width:20%">
                                <i class="aui-iconfont aui-icon-lock" style="margin: 0 auto;font-size: 0.5rem;"></i>
                            </div>
                            <div class="aui-list-item-input">
                                <input id="passwordLogin" style="height:1.2rem;line-height:1.2rem;font-size:0.4rem" type="password" placeholder="请输入密码">
                            </div>
                        </div>
                    </li>
                </ul>
            </div>
            <p><div class="aui-btn aui-btn-block aui-btn-sm" tapmode onclick="numberLoginFun()">登&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;录</div></p>
        </div>
        <div style="position:absolute;bottom:1rem;width: 100%;">
            <p style="font-size:0.32rem;color:#333;text-align:center;">登录即代表您同意
              <span style="color:#ff4c41;" tapmode onclick="explain()">《用户协议》</span>和
              <span style="color:#ff4c41;"  tapmode onclick="explain()">《隐私协议》</span></p>
        </div>
    </div>
</body>
<script type="text/javascript" src="../../script/api.js"></script>
<script type="text/javascript" src="../../script/vue.min.js"></script>
<script type="text/javascript" src="../../script/common.js"></script>
<script type="text/javascript">
(function (doc, win) {
  	var docEl = doc.documentElement,
  	resizeEvt = 'orientationchange' in window ? 'orientationchange' : 'resize',
  	recalc = function () {
    		var clientWidth = docEl.clientWidth;
    		if (!clientWidth) return;
    		docEl.style.setProperty('font-size',(clientWidth / 10) + 'px','important');
  	};
  	if(!doc.addEventListener){
        return
    };
  	win.addEventListener(resizeEvt, recalc, false);
  	doc.addEventListener('DOMContentLoaded', recalc, false);
})(document, window);
var wx,config_info;
apiready = function () {
		//解析元素 tapmode 属性，优化点击事件处理 - 第四步
		api.parseTapmode();
    var header = $api.byId('aui-header');
		$api.fixStatusBar(header);
    wx = api.require('wx');
    config_info = api.getGlobalData({
      key: 'config_info'
    });
    if (api.systemType == "ios") {
        if (config_info.format_type) {
            $api.css($api.dom(".accountNumber"), 'display:block;');
            $api.css($api.dom(".wxBox"), 'display:none;');
        }
    }
    // 打开当前对应frm页面
    api.addEventListener({
        name: 'keyback'
    }, function (ret, err) {
        var frames = api.frames();
        if (frames.findIndex(item => {
            return item.name == "explain"
        }) != -1) {
            api.closeFrame({
                name: "explain"
            });
        } else {
            api.closeWin({});
        }
    });
}
// 登录
function wxlogin() {
    if (api.systemType != "ios") {
        wx.isInstalled(function (ret, err) {
            if (ret.installed) {
                wxAuth();
            } else {
                api.toast({
                    msg: '请安装微信客户端后重试',
                    duration: 2000,
                    location: 'middle'
                });
            }
        });
    } else {
        wxAuth();
    }
}
// 用户协议
function explain() {
    api.openFrame({
        reload: true,
        name: 'explain',
        url: '../explain.html',
        bgColor: "rgba(0,0,0,0.2)",
        animation: {
            type: "none",
        },
        pageParam: {
            type: 1
        }
    });
}
// 微信登录
function wxAuth() {
    wx.auth(function (ret, err) {
        if (ret.status) {
            $api.ajax({
                url: 'api/account/oauth',
                method: 'POST',
                data: {
                    values: {
                        device_id: '',
                        wx_code: ret.code,
                    }
                }
            }, function (r) {
                $api.setStorage('token', r.data.token);
                aJpushIDFun();
                memberInfo();
            });
        } else {
            api.toast({
                msg: '微信登录失败,请重试',
                duration: 2000,
                location: 'middle'
            });
        }
    });
}
// 用户登陆信息
function memberInfo() {
    $api.ajax({
        url: 'api/member/info',
        method: 'get',
    }, function (ret) {
        api.setGlobalData({
            key: 'member_info',
            value: ret.data.info,
        });
        systemInfo();
    });
}
function systemInfo() {
    $api.ajax({
        url: 'api/system/info',
        method: 'get',
    }, function (ret) {
        api.setGlobalData({
            key: 'system_info',
            value: ret.data.info,
        });
        closeWinFun();
    });
}

// 账号密码登录
function numberLoginFun(){
    if ($.trim($api.dom("#numberLogin").value).length > 0 && $.trim($api.dom("#passwordLogin").value).length > 0) {
        $api.ajax({
            url: 'api/account/login',
            method: 'POST',
            data: {
                values: {
                    relation_id: $.trim($api.dom("#numberLogin").value),
                    password: $.trim($api.dom("#passwordLogin").value),
                }
            }
        }, function (r) {
            $api.setStorage('token', r.data.token);
            memberInfo();
        });
    }
}
// 关闭当前页面
function closeWinFun(){
    api.closeWin({});
}
</script>
</html>
